package com.jwcao.common.cast.annotation.factory;

import com.jwcao.common.cast.annotation.CastField;
import java.lang.reflect.Field;
import java.util.Arrays;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;

/**
 * name: CastFieldFactory description: TODO
 *
 * @author caojingwei date: 2023/3/24 19:42
 */
public class CastFieldFactory {

    public static CastField get(String id, Field field) {
        CastField[] castFields = field.getAnnotationsByType(CastField.class);
        if (ArrayUtils.isNotEmpty(castFields)) {
            return Arrays.stream(castFields)
                .filter(c -> StringUtils.equals(c.id(), id))
                .findAny().orElse(null);
        }
        return null;
    }
}
